package com.example.yuejian.yuejian.model;

import com.example.yuejian.yuejian.base.ModleListListener;
import com.example.yuejian.yuejian.base.ModleListener;
import com.example.yuejian.yuejian.bean.EditAddress;
import com.example.yuejian.yuejian.bean.EditNickname;
import com.example.yuejian.yuejian.bean.EditPassword;
import com.example.yuejian.yuejian.bean.Login;
import com.example.yuejian.yuejian.bean.MyFollowMaster;
import com.example.yuejian.yuejian.bean.MyPrize;
import com.example.yuejian.yuejian.bean.Order;
import com.example.yuejian.yuejian.bean.OrderDetail;
import com.example.yuejian.yuejian.bean.Register;
import com.example.yuejian.yuejian.bean.ShowPhotoList;
import com.example.yuejian.yuejian.bean.Tuikuan;
import com.example.yuejian.yuejian.bean.UsersInfo;
import com.example.yuejian.yuejian.service.LoginService;
import com.example.yuejian.yuejian.service.RegisterService;
import com.example.yuejian.yuejian.service.UserService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2017/9/13.
 */

public class UserModel {
    private Retrofit retrofit;
    public UserModel(){
        retrofit=new Retrofit.Builder()
                .addConverterFactory(GsonConverterFactory.create())
                .baseUrl(Contants.BASE_URL)
                .build();

    }
    //登录
    public void userLogin(String telephone, String password, final ModleListener listener){
        LoginService service=retrofit.create(LoginService.class);
        Call<Login>call=service.login(telephone,password);
        call.enqueue(new Callback<Login>() {
            @Override
            public void onResponse(Call<Login> call, Response<Login> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                } else
                    listener.onFail("onresponse fail");

            }

            @Override
            public void onFailure(Call<Login> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });

    }
    //注册
    public  void Register(String password,String rePassword,String telephone, String nickname,final ModleListener modleListener)
    {
        RegisterService service=retrofit.create(RegisterService.class);
        Call<Register> call=service.register(password,rePassword,telephone,nickname);
        call.enqueue(new Callback<Register>() {
            @Override
            public void onResponse(Call<Register> call, Response<Register> response) {
                if (response.isSuccessful() && response.body() != null) {
                    modleListener.onResponse(response.body());
                } else
                    modleListener.onFail("onresponse fail");

            }

            @Override
            public void onFailure(Call<Register> call, Throwable t) {
                modleListener.onFail(t.toString());
            }
        });
    }
    //我的奖品
    public  void myPrizeList(String users_id, final ModleListListener listListener)
    {
        UserService service=retrofit.create(UserService.class);
         Call <List<MyPrize>>call=service.myprize(users_id);
        call.enqueue(new Callback<List<MyPrize>>() {
            @Override
            public void onResponse(Call<List<MyPrize>> call, Response<List<MyPrize>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listListener.onResponse(response.body());
                } else
                    listListener.onFail("onresponse fail");

            }

            @Override
            public void onFailure(Call<List<MyPrize>> call, Throwable t) {
                listListener.onFail(t.toString());
            }
        });

    }
    //个人信息

    public  void userInfo(String users_id,final ModleListener modleListener)
    {
        UserService service=retrofit.create(UserService.class);
        Call<UsersInfo>call=service.userinfo(users_id);
        call.enqueue(new Callback<UsersInfo>() {
            @Override
            public void onResponse(Call<UsersInfo> call, Response<UsersInfo> response) {
                if (response.isSuccessful()&&response.body()!=null)
                {
                    modleListener.onResponse(response.body());
                }
                else
                    modleListener.onFail("shibai");
            }

            @Override
            public void onFailure(Call<UsersInfo> call, Throwable t) {
                modleListener.onFail(t.toString());
            }
        });



    }
  //我的关注
    public  void  MyfollowList(String users_id,final ModleListListener listListener)
    {
        UserService service=retrofit.create(UserService.class);
        Call<List<MyFollowMaster>>call=service.myFollowlist(users_id);
        call.enqueue(new Callback<List<MyFollowMaster>>() {
            @Override
            public void onResponse(Call<List<MyFollowMaster>> call, Response<List<MyFollowMaster>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listListener.onResponse(response.body());
                } else
                    listListener.onFail("onresponse fail");

            }

            @Override
            public void onFailure(Call<List<MyFollowMaster>> call, Throwable t) {
                listListener.onFail(t.toString());
            }
        });

    }
    //我的订单
    public  void myOrderList(String users_id,final ModleListListener listListener)
    {
        UserService service=retrofit.create(UserService.class);
        Call <List<Order>>call=service.myOrderList(users_id);
        call.enqueue(new Callback<List<Order>>() {
            @Override
            public void onResponse(Call<List<Order>> call, Response<List<Order>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listListener.onResponse(response.body());
                } else
                    listListener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<List<Order>> call, Throwable t) {
                listListener.onFail(t.toString());
            }
        });
    }

    //修改性别
   public  Call Editgender(String users_id,String  gender)
    {
        UserService service=retrofit.create(UserService.class);
        return  service.editGender(users_id,gender);

    }
/*public  void Editgender(String id,String gender ,final ModleListener listener)
    {
        UserService service=retrofit.create(UserService.class);
        Call<EditGender>call=service.editGender(id,gender);
        call.enqueue(new Callback<EditGender>() {
            @Override
            public void onResponse(Call<EditGender> call, Response<EditGender> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                } else
                    listener.onFail("onresponse fail");

            }

            @Override
            public void onFailure(Call<EditGender> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }*/

//修改昵称
    public void EditNickName(String userid,String nickname,final ModleListener modleListener)
    {
        UserService userService=retrofit.create(UserService.class);
        Call<EditNickname>call=userService.editNickname(userid,nickname);
        call.enqueue(new Callback<EditNickname>() {
            @Override
            public void onResponse(Call<EditNickname> call, Response<EditNickname> response) {
                if (response.isSuccessful() && response.body() != null) {
                    modleListener.onResponse(response.body());
                } else
                    modleListener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<EditNickname> call, Throwable t) {
                modleListener.onFail(t.toString());
            }
        });
    }
    //修改地址
    public  void EditAddress(String userid,String address,final ModleListener listener)
    {
        UserService userService=retrofit.create(UserService.class);
        Call<EditAddress>call=userService.editAddress(userid,address);
        call.enqueue(new Callback<EditAddress>() {
            @Override
            public void onResponse(Call<EditAddress> call, Response<EditAddress> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                } else
                    listener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<EditAddress> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
    //修改密码
    public void EditPassword(String userid,String oldpwd,String pwd,String repwd,final ModleListener listener)
    {
        UserService service=retrofit.create(UserService.class);
        Call<EditPassword>call =service.editPwd(userid,oldpwd,pwd,repwd);
        call.enqueue(new Callback<EditPassword>() {
            @Override
            public void onResponse(Call<EditPassword> call, Response<EditPassword> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                } else
                    listener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<EditPassword> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }

    public  void MyShowPhotoList(String usersid,final  ModleListListener listListener)
    {
        UserService service=retrofit.create(UserService.class);
        Call<List<ShowPhotoList>>call=service.myShowPhotoList(usersid);
        call.enqueue(new Callback<List<ShowPhotoList>>() {
            @Override
            public void onResponse(Call<List<ShowPhotoList>> call, Response<List<ShowPhotoList>> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listListener.onResponse(response.body());
                } else
                    listListener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<List<ShowPhotoList>> call, Throwable t) {
                listListener.onFail(t.toString());
            }
        });
    }
    public void OrderDetail(String order_id,final ModleListener listener)
    {
        UserService service=retrofit.create(UserService.class);
        Call<OrderDetail>call=service.order_detail(order_id);
        call.enqueue(new Callback<OrderDetail>() {
            @Override
            public void onResponse(Call<OrderDetail> call, Response<OrderDetail> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                } else
                    listener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<OrderDetail> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
    public void Tuikuan(String userid,String orderid,final ModleListener listener)
    {
        UserService service=retrofit.create(UserService.class);
        Call<Tuikuan>call=service.tuikuan(userid,orderid);
        call.enqueue(new Callback<Tuikuan>() {
            @Override
            public void onResponse(Call<Tuikuan> call, Response<Tuikuan> response) {
                if (response.isSuccessful() && response.body() != null) {
                    listener.onResponse(response.body());
                } else
                    listener.onFail("onresponse fail");
            }

            @Override
            public void onFailure(Call<Tuikuan> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
}
